package rs.ac.mbs2.entiteti;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name = "putnik")
public class Putnik extends Korisnik {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "putnik")
	private Set<Voznja> voznje = new HashSet<Voznja>();
	
	public void add(Voznja v)
	{
		if (v.getPutnik() != null) 
			v.getPutnik().getVoznje().remove(v);
			v.setPutnik(this);
			voznje.add(v);
	}
	
	public void remove(Voznja v) {
		v.setPutnik(null);
		voznje.remove(v);
	}
	
	//costrruct
	
	public Putnik(){super();}
	
	public Putnik(
			Long jmbg,
			 String ime,
			 String prezime,
			 String korisnickoIme,
			 String lozinka
			){
		super(jmbg, ime, prezime, korisnickoIme, lozinka);
	}
	//get set
	public Set<Voznja> getVoznje() {
		return voznje;
	}
	public void setVoznje(Set<Voznja> voznje) {
		this.voznje = voznje;
	}
	
	
	public String toString()
	{
		return "Putnik [" + super.toString() + "]";
	}
}
